class dealNetWork {
    constructor () {
        super()
    }
}
// 获取网络质量
class getQuality extends dealNetWork {
    //检测网络情况
    onConnectionChange() { 
        const { rtt, downlink, effectiveType, saveData } = navigator.connection;
        const online=navigator.onLine
        // console.log(`网路类型${effectiveType}`)
        // console.log(`带宽${downlink}Mb/s`)
        // console.log(`往返时间${rtt}`)
        // console.log(`打开/请求数据保护模式${saveData}`)
        // console.log(`是否断网${online}`)
        return {
            rtt,downlink,effectiveType,saveData,online
        }
    }
    //检测是否连接网络
    watchOnline() { 
        return new Promise((resolve) => { 
             window.addEventListener("online", () => {
                resolve(true)
              });
        }) 
    }
    //检测是否重新连接成功
    watchOffline() { 
        return new Promise((resolve) => { 
            window.addEventListener("online", () => {
               resolve(false)
             });
       }) 
    }
   
}

export default dealNetWork